<?php
/**
 * [group ]
 * @author  liugang
 * @date    2019-07-19 14:49:53
 * @version [0.1]
 * @param $total [总人数]
 * @param $group_item_num [每个房间人数]
 * @param $which_people [要查询的第几个人的，如要查询第8个人在哪个房间$which_people=8]
 * @return string
 */
class Tool{
    public function group($total,$group_item_num,$which_people){
        $arr = [];
        for ($i = 1;$i <= $total;$i++){
            $arr[$i] = $i;
        }
        $groups = array_chunk($arr,$group_item_num);
        $return = '没有查询到数据';
        foreach ($groups as $k=>$group){
            if (in_array($which_people,$group)){
                $return = '第'.$which_people.'个人在'.($k+1).'房间';
                break;
            }
        }
        return $return;
    }

    public function group2($group_item_num,$which_people){
        $y = $which_people/$group_item_num;
        $m = $which_people%$group_item_num;
        if($m == 0){
            return $y;
        }else{
            // $y = $y+ 1;
            // return intval($y);
            return ceil($y);
            //return $y
            //return intval($y);
        }
    }
}

//example1
$tool = new Tool();
// echo "".PHP_EOL;
// echo "example1:";
// echo $tool->group(13,3,7);
// echo PHP_EOL;
// echo "取模:";
// echo $tool->group2(3,7);

// //example2
// echo "".PHP_EOL;
// echo "example2:";
// echo $tool->group(13,6,7);
// echo PHP_EOL;
// echo "取模:";
// echo $tool->group2(6,7);


//推送起飞
//todo 当前总数
//todo  当前数.


//每遇到6 重置房间;即房间数++
//动作驱动。事件驱动。
//fd已知。容纳人数已知
//fd6 house1 除了分配房间还有发送 开始
//fd7 house2

//$fd
//房间等待中

echo "test start      ";
$m = 7%6;
echo $m;

echo "       test end";

echo "start:".PHP_EOL;
$setC = 6;
$fd =1;
echo "所处".$tool->group2($setC,$fd);
//$house_array = [];
$house_key = $tool->group2($setC,$fd);
//$house_array
//$house_val =array_values();

//1%6 会Exception
$fd = 6;
echo "所处".$tool->group2($setC,$fd);

$fd = 7;
echo "所处".$tool->group2($setC,$fd);

//print_r(array_values($arr));
//$array[] = $value。
//array_push()
//
echo "数组：".PHP_EOL;
$arrBig = array();
$val = array();
array_push($val,1);
print_r($val);
$val = array_values($val);
array_push($val,2);
print_r($val);



//print_r($val);
// print_r($val2);
// print_r($value);


//array_push($arrBig,$val); //大key 不能用array_push


$fd = 1;
if(isset($arrBig[$fd])){
    $val = $arrBig[$fd];  
}else{
    $val = array();
}
array_push($val,$fd); //不管是不是空null?都可以是 push
$arrBig[$fd] = $val;
print_r($arrBig);





//print_r($val);
// array_push($val,1);
// print_r($arrBig);
// $arrBig[$fd] = $val;
// print_r($arrBig);
// $arrBig[8]=1;
// print_r($arrBig);